package com.huawei.od.c.easy.t6;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class T6 {
    //素数 2 3 5 7 11 13 17 19 23 27 29 ...
    public static void main(String[] args) {
        t6(29*19);
    }

    private static void t6(int i) {
        List<int[]> ysList = getYSList(i);

        for (int[] ints : ysList) {
            if (meetSS(ints[0], ints[1])) {
                System.out.println(ints[0] + " " + ints[1]);
            }
        }
    }

    private static boolean meetSS(int anInt, int anInt1) {
        return meetSS(anInt) && meetSS(anInt1);
    }

    private static boolean meetSS(int i) {
        for (int j = 2; j <= i / 2; j++) {
            if (i % j == 0) {
                return false;
            }
        }
        return true;
    }

    private static List<int[]> getYSList(int i) {
        List<int[]> list = new ArrayList<>();
        Map<Integer, Integer> keyMap = new HashMap<>();
        for (int j = 2; j < i / 2; j++) {
            if (i % j == 0) {
                int[] arr = new int[2];
                int y1 = i / j;
                if (keyMap.containsKey(j)) {
                    continue;
                } else {
                    keyMap.put(j, 0);
                    keyMap.put(y1, 0);
                    if (j < y1) {
                        arr[0] = j;
                        arr[1] = y1;
                    } else {
                        arr[1] = j;
                        arr[0] = y1;
                    }
                    list.add(arr);
                }
            }
        }
        return list;
    }
}
